package com.nbsaas.boot.app.data.entity;

import com.nbsaas.boot.code.annotation.*;
import com.nbsaas.boot.jpa.data.entity.LongEntity;
import com.nbsaas.boot.rest.filter.Operator;
import lombok.Data;
import org.hibernate.annotations.Comment;

import javax.persistence.*;

@ComposeView
@FormAnnotation( model = "角色")
@Data
@Entity
@org.hibernate.annotations.Table(appliesTo = "sys_app_role_menu",comment = "应用角色菜单")
@Table(name = "sys_app_role_menu")
public class AppRoleMenu extends LongEntity {

    @JoinColumn(name = "role_id")
    @FieldConvert
    @Comment("角色id")
    @ManyToOne(fetch = FetchType.LAZY)
    private AppRole role;

    @JoinColumn(name = "app_id",foreignKey = @ForeignKey(ConstraintMode.PROVIDER_DEFAULT))
    @Comment("应用")
    @SearchItem(label = "应用", name = "app", key = "app.id", operator = Operator.eq)
    @FieldName
    @FieldConvert
    @ManyToOne(fetch = FetchType.LAZY)
    private App app;

    @JoinColumn(name = "menu_id")
    @FieldConvert
    @Comment("菜单id")
    @ManyToOne(fetch = FetchType.LAZY)
    private AppMenu menu;
}
